﻿namespace WpInsights.Migrator
{
    using System;
    using System.Configuration;
    using System.Reflection;

    using WpInsights.Core;

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("WpInsights Migrator:");
                if (args.Length == 0)
                {
                    Console.WriteLine("Usage: WpInsights.Migrator.exe <Excel File Path>");
                }
                else
                {
                    string fileName = args[0];
                    EnvironmentSettings settings = new EnvironmentSettings();
                    settings.DataWriterUrl = ConfigurationManager.AppSettings["DataWriterUrl"];
                    settings.VsoAccountId = ConfigurationManager.AppSettings["VsoAccountId"];
                    if (string.IsNullOrEmpty(settings.VsoAccountId))
                    {
                        Console.WriteLine("Please specify VsoAccountId in WpInsights.Migrator.exe.config file.\nYou can retrieve it at https://<YourAccountName>.visualstudio.com/_appanalytics/_admin/keysanddownloads in Account ID text field");
                    }
                    else 
                    {
                        settings.PrimaryKey = ConfigurationManager.AppSettings["PrimaryKey"];
                        if (string.IsNullOrEmpty(settings.PrimaryKey))
                        {
                            Console.WriteLine(
                                "Please specify VsoAccountId in WpInsights.Migrator.exe.config file.\nYou can retrieve it at https://<YourAccountName>.visualstudio.com/_appanalytics/_admin/keysanddownloads in Primary instrumentation key text field");
                        }
                        else
                        {
                            Console.WriteLine("DataWriterUrl: " + settings.DataWriterUrl);
                            Console.WriteLine("VsoAccountId: " + settings.VsoAccountId);
                            Console.WriteLine("PrimaryKey: " + settings.PrimaryKey);
                            Iterator.Process(fileName, settings);
                        }
                    }
                }

                Console.WriteLine("\nPress enter to exit.");
                
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

